package midend.IR_Value;

import midend.IR_Type.IR_Const;
import midend.IR_Type.IR_Type;

public class IR_VirtualReg_Value extends IR_Value{
    /*
     * 该类是虚拟寄存器的引用，用于表示虚拟寄存器
     * 例如 %tmp1
     * 一般会有alloca指令为其分配空间
     */
    static int tempCounter = 0;
    private final String identity;/*虚拟寄存器的标识符*/
    private IR_Type type;/*虚拟寄存器所对应变量的类型*/
    private final int tempNO;
    public IR_VirtualReg_Value(String identity, IR_Type type) {
        this.tempNO = tempCounter++;
        this.type = type;
        this.identity = identity;
    }
    @Override
    public String get_ValueName() {
        return "%" + this.identity + tempNO;
    }
    @Override
    public IR_Type get_Type() {
        return type;
    }
    @Override
    public int get_Const_Type() {
        return IR_Const.IR_Instruction;
    }
    public String getIdentity(){return identity;}

    @Override
    public String toString() {
        return "IR_VirtualReg:" + this.identity + "    type" + type;
    }
}
